<?php

namespace app\common\library;
require_once '../vendor/qiniu/php-sdk/autoload.php';

use think\Controller;
use think\Db;
use Qiniu\Auth;
use Qiniu\Storage\BucketManager;
use Qiniu\Config as QiniuConfig;
use Qiniu\Storage\UploadManager;
use think\facade\Config;
use think\facade\Request;

class Qiniu extends Controller
{
    protected $config = [
        'bucket' => '',
        'accessKey' => '',
        'secretKey' => ''
    ];
    // 实例化并传入参数
    public function __construct()
    {
        $this->config['bucket'] = config('param.bucket');
        $this->config['accesskey'] = config('param.accesskey');
        $this->config['secretkey'] = config('param.secretkey');
    }


    public function downloadurl($file)
    {
        $auth = new Auth($this->config['accesskey'], $this->config['secretkey']);
        $baseUrl = 'https://file.weibuyun.com/' . $file;
        $this->redirect($auth->privateDownloadUrl($baseUrl,120), 302);
    }
    public function getimgurl($file)
    {
        $auth = new Auth($this->config['accesskey'], $this->config['secretkey']);
        $baseUrl = 'https://file.weibuyun.com/' . $file;
        return $auth->privateDownloadUrl($baseUrl,120);
    }

}